package GUItest;
import java.sql.*;

public class DataBaseHandler
{
	private Statement stmt = null;
	private ResultSet rs; 
	private Connection con;
	
	public DataBaseHandler(Connection con)
	{
		this.con = con;

		try {
			stmt = con.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public void updateDateBase(String q)
	{
		try {
			stmt.execute(q);
		} catch (SQLException e) {
			System.err.print("Cannot update database");
			e.printStackTrace();
		}
	}
	
	public String[][] query(String q, int numCol, int numRow)
	{
		String[][] result = new String[numCol][numRow];
		try {
			rs = stmt.executeQuery(q);
			
			int x = 0;
			while(rs.next())
			{
				for(int y = 0; y < numCol; y++)
				{
					result[x][y] = rs.getString(y + 1);
				}
				x++;
			}
			
		} catch (SQLException e) {
			System.err.println("Cannot return queury");
			e.printStackTrace();
		}
		
		return result;
	}
	
}
